package java基础;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;

public class List去重 {
    public static void main(String[] args) {
        //1
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> list2 = new ArrayList<>(new LinkedHashSet<>(list));
        list2.forEach(s -> System.out.println(s));
        //2
        List<Integer> list3 = new ArrayList<>();
        for (Integer integer : list) {
            if (!list3.contains(integer)) {
                list3.add(integer);
            }
        }
        list3.forEach(s -> System.out.println(s));
        //3
        List<Integer> collect = list.stream().distinct().collect(Collectors.toList());
        System.out.println(collect);
    }
}
